package com.itheima.stock.controller.v1;

import com.itheima.stock.annotation.Limiter;
import com.itheima.stock.api.UserControllerAPI;
import com.itheima.stock.dto.LoginDTO;
import com.itheima.stock.response.ResponseResult;
import com.itheima.stock.service.UserService;
import com.itheima.stock.vo.CaptchaVO;
import com.itheima.stock.vo.LoginVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zby
 * @created 2024-06-22 22:48
 * @description 用户接口实现
 */
@RestController
public class UserController implements UserControllerAPI {

  private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    /**
     * 用户登录
     * @param loginDTO
     * @return
     */
    @Override
    public ResponseResult<LoginVO> login(LoginDTO loginDTO) {
        return ResponseResult.ok(userService.login(loginDTO));
    }

    /**
     * 生成验证码,进行流量控制，通过aop技术加guava限流limiter
     * @return
     */
    @Limiter
    @Override
    public ResponseResult<CaptchaVO> captcha() {
        return ResponseResult.ok(userService.captcha());
    }

    @Override
    public String getName(String name) {
//        Exceptions.cast(CodeEnum.DATA_ERROR);
//        int a = 1/0;
        return "itheima  " + name;
    }
}